package ldh.fx.adminfx.controller;

import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.geometry.Orientation;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.TilePane;
import javafx.scene.layout.VBox;
import javafx.scene.shape.Circle;
import ldh.fx.adminfx.pojo.Fans;

import java.net.URL;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;

public class PeopleController implements Initializable {

    @FXML private TilePane followPane;
    @FXML private ChoiceBox<Fans> peopleGroupChoiceBox;

    @Override
    public void initialize(URL url, ResourceBundle resourceBundle) {
        followPane.setOrientation(Orientation.HORIZONTAL);
        followPane.setAlignment(Pos.CENTER);
        followPane.setHgap(30);
        followPane.setVgap(20);

        List<Fans> fansList = loadFansList();
        for(Fans fans : fansList) {
            followPane.getChildren().add(createItem(fans));
        }
    }

    private Node createItem(Fans fans) {
        VBox vBox = new VBox(10);
        vBox.getStyleClass().add("item");
        ImageView imageView = new ImageView();
        Image image = new Image(this.getClass().getResource(fans.getHeadIconUrl()).toExternalForm());
        imageView.setImage(image);
        imageView.setFitHeight(100);
        imageView.setFitWidth(100);
        Circle circle = new Circle(50, 50, 50);
        imageView.setClip(circle);

        Label name = new Label(fans.getUserName());
        name.getStyleClass().add("h4");
        Label motto = new Label(fans.getMotto());

        vBox.getChildren().addAll(imageView, name, motto);
        return vBox;
    }

    private List<Fans> loadFansList() {
        List<Fans> fansList = new ArrayList();
        for(int i=0; i<60; i++) {
            Fans fans = new Fans();
            fans.setHeadIconUrl("/img/fans/t1.jpg");
            fans.setUserName("demo " + i);
            fans.setMotto("hello world");
            fansList.add(fans);
        }
        return fansList;
    }
}
